load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:defs.bzl", "rust_test_suite_with_extra_srcs")

package(default_visibility = ["//visibility:public"])

DEPENDENCIES = [
    # Keep sorted.
    "//rs/canonical_state",
    "//rs/config",
    "//rs/crypto/tls_interfaces",
    "//rs/crypto/tree_hash",
    "//rs/interfaces",
    "//rs/interfaces/certified_stream_store",
    "//rs/interfaces/registry",
    "//rs/interfaces/state_manager",
    "//rs/limits",
    "//rs/monitoring/logger",
    "//rs/monitoring/metrics",
    "//rs/protobuf",
    "//rs/registry/helpers",
    "//rs/registry/keys",
    "//rs/registry/subnet_type",
    "//rs/replicated_state",
    "//rs/types/base_types",
    "//rs/types/types",
    "//rs/xnet/hyper",
    "//rs/xnet/uri",
    "@crate_index//:http-body-util",
    "@crate_index//:hyper",
    "@crate_index//:hyper-util",
    "@crate_index//:prometheus",
    "@crate_index//:rand",
    "@crate_index//:slog",
    "@crate_index//:thiserror",
    "@crate_index//:tokio",
]

MACRO_DEPENDENCIES = [
    # Keep sorted.
    "@crate_index//:async-trait",
]

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//rs/crypto/tls_interfaces/mocks",
    "//rs/interfaces/certified_stream_store/mocks",
    "//rs/interfaces/state_manager/mocks",
    "//rs/registry/fake",
    "//rs/registry/proto_data_provider",
    "//rs/state_manager",
    "//rs/test_utilities",
    "//rs/test_utilities/consensus",
    "//rs/test_utilities/logger",
    "//rs/test_utilities/metrics",
    "//rs/test_utilities/registry",
    "//rs/test_utilities/state",
    "//rs/test_utilities/time",
    "//rs/test_utilities/types",
    "@crate_index//:assert_matches",
    "@crate_index//:axum",
    "@crate_index//:maplit",
    "@crate_index//:mockall",
    "@crate_index//:nix",
    "@crate_index//:proptest",
    "@crate_index//:reqwest",
    "@crate_index//:tempfile",
    "@crate_index//:url",
]

MACRO_DEV_DEPENDENCIES = [
    # Keep sorted.
    "@crate_index//:test-strategy",
]

rust_library(
    name = "payload_builder",
    srcs = glob(["src/**"]),
    crate_name = "ic_xnet_payload_builder",
    proc_macro_deps = MACRO_DEPENDENCIES,
    version = "0.9.0",
    deps = DEPENDENCIES,
)

rust_test(
    name = "payload_builder_test",
    crate = ":payload_builder",
    proc_macro_deps = MACRO_DEV_DEPENDENCIES,
    deps = DEV_DEPENDENCIES,
)

rust_test_suite_with_extra_srcs(
    name = "payload_builder_integration",
    srcs = [
        "tests/certified_slice_pool.rs",
        "tests/xnet_payload_builder.rs",
    ],
    extra_srcs = [
        "tests/common/mod.rs",
    ],
    proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
    deps = DEPENDENCIES + DEV_DEPENDENCIES + [":payload_builder"],
)
